<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 实现trim(str)方法，过滤字符串首位空白 -->
    <script>
        let str = prompt('请输入内容');

        function trim(str) {
            //匹配全局空白区域
            // const reg = /\s+/g;

            //匹配首尾空白区域
            const reg = /^\s+|\s+$/g;
            str = str.replace(reg, '');
            console.log(str);
        };
        trim(str);
    </script>
</body>

</html>